#!/usr/bin/env python
""" Common helper functions."""
__author__      = "Michael J. Hohmann"
__copyright__   = "Copyright 2017, Linde Material Handling GmbH"
__versio__      = "0.0.1"
__email__       = "michael.hohmann@lind-mh.de"
__status__      = "Prototype"
__date__        = "2017-02-20"

def dict_test(dict,key,value):
    if key in dict.keys():
        if dict[key] == value:
            return True
    return False
    
def defaultdict( d,key, default):
    if key in d:        
        return d[key]
    else:
        return default
        
def change_file_ending( filename, new_ending):
        import os
        head,tail = os.path.split(filename)
        
        file_component=tail.split('.')
        if len(file_component)>1:
            file_component=file_component[:-1]      
            new_filename=''
            for item in file_component:
                new_filename+=item+'.'
        else:
            new_filename=tail+'.'
        
        new_filename+=new_ending        
        return os.path.join(head,new_filename,)
        